package cn.codelab.seata.storage.service.impl;

import cn.codelab.seata.storage.entity.Storage;
import cn.codelab.seata.storage.mapper.StorageMapper;
import cn.codelab.seata.storage.service.StorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Seven
 * @description
 * @博客：https://codelab7.cn
 * @Gitee https://gitee.com/it-codelab
 * @Copyright 公众号：Seven的代码实验室
 */
@Slf4j
@Service
public class StorageServiceImpl extends ServiceImpl<StorageMapper, Storage> implements StorageService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean dedt(long productId, long used) {
        int index = this.baseMapper.updateUsed(productId, used);
        // 模拟异常
//        int i = 1/0;
        return index > 0;
    }
}
